package mx.iteso.comp.logo;

import mx.iteso.comp.logo.parser.*;
import mx.iteso.comp.logo.lexer.*;
import mx.iteso.comp.logo.node.*;
import java.io.*;


public class Compiler
{
		
		public static String Compiler(String instructions) {
			String output = ""; Conector.setOutput("");
	        try {
//	            System.out.println("Se esta haciendo el analisis lexico y semantico =)");


	            // Create a Parser instance.
	            Parser p =
	                    new Parser(
	                    new Lexer(
	                    new PushbackReader(
	                    new StringReader(instructions), 1024)));


	            // Parse the input.
	            Start tree = p.parse();
	            output += tree;


	            // Apply the translation.
	            tree.apply(new Translator());
	            output += (Conector.getOutput().equals(" ")?"":("\n\rOutput:"+Conector.getOutput()));
	        } catch (Exception e) {
				output += "\n\rError: " + instructions ;
	            output += e.getMessage();
	        }
			return output;
	    }
	}
